# 字典的本质 人为设置的映设关系  key value
dic = {
    "alex": "人",
    "yuh": "zhang"
}
print(dic["alex"])
print(dic["yuh"])

# key 再python中必须是可hash类型 数字 字符串 元祖
a = 10
dic= {
    "name":"zhang",
    22: 99,
    (1,2,3):"abc",
    a:10
}


# 增删该查 给key和value就可以存储
# 字典中的key是唯一的
addDic = {
    "name": "zhang",
}
addDic["age"] = 18
addDic["name"] = "zhangYuhang"

# 删除不常用

# 查询 必须要有key
print(addDic["name"]) # key不存在程序报错
print(addDic.get("name")) # 找不到返回null *
# 循环 使用的概率比较低 -> 不要见到字典就循环
for i in addDic:
    print(i, addDic.get(i))


for key, value in addDic.items():
    print(key, value)

# 嵌套 -> 解析  一层一层找
wf = {
    "name": "wangfeng",
    "age": 17,
    "wife": {
        "name": "zhang",
        "age": 18,
        "hobby": ["唱"]
    },
    "children": [
        {"name": "zhang", "age": 18, "hobby": ["唱", "跳", "rap"]},
        {"name": "li", "age": 18, "hobby": ["唱", "跳", "rap"]}
    ],
}

# wf的名字
print(wf["name"])

# wf老婆的名字
print(wf["wife"]["name"])

